#!/bin/bash
#
# 4shared.com module
# Copyright (c) 2010-2012 Plowshare team
#
# This file is part of Plowshare.
#
# Plowshare is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Plowshare is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Plowshare.  If not, see <http://www.gnu.org/licenses/>.

MODULE_SHARE-ONLINE_BIZ_REGEXP_URL="http://\(www\.\)\?share-online\.biz/"

MODULE_SHARE-ONLINE_BIZ_DOWNLOAD_OPTIONS=""
MODULE_SHARE-ONLINE_BIZ_DOWNLOAD_RESUME=yes
MODULE_SHARE-ONLINE_BIZ_DOWNLOAD_FINAL_LINK_NEEDS_COOKIE=yes

MODULE_SHARE-ONLINE_BIZ_LIST_OPTIONS=""

share-online_biz_download() {

local COOKIEFILE=$1
local URL=$2

	Pageinit=$(curl -c "$COOKIEFILE" "$URL") || return

	curl -b "$COOKIEFILE" -d "dl_free=1&choice=free" "$URL" || return

	Pageauth=$(curl -b "$COOKIEFILE" "$URL") || return

	getreq=$(echo "$Pageauth" | grep /get)
	getreq=${getreq:12}
	getreq=${getreq%?}
	getreq=${getreq%?}
	getreq=${getreq%?}
	baseurl=$(basename_url "$URL")
     	getreq="$baseurl$getreq"

	Pagexmllink=$(curl -b "$COOKIEFILE" "$getreq") || return
	finallink=$(echo "$Pagexmllink" | sed 's/http:\/\/media/\^http:\/\/media/g' | tr -s "^" "\n" | grep http| sed 's/\ .*//g' | grep http)

	FILE_URL=${finallink%?}
	FILENAME="$tryingsomethingcompletelydifferent1"
	
	echo "$FILE_URL"
	echo "$FILENAME"
